<?php
/**
 * clspermission
 * controller for permission table 
 * @package naanal
 */
class ClsPermission
{
	
        /**
         * request
         * @package naanal
         * @var string 
         */
	public $request=null;
        /**
         * get
         * @package naanal
         * @var string 
         */
	public $get=null;
        /**
         * post
         * @package naanal
         * @var string 
         */
	public $post=null;
        /**
         * files
         * @package naanal
         * @var string 
         */
	public $files=null;
        /**
         * pdo
         * @package naanal
         * @var string 
         */
	public $pdo=null;
        /**
         * controlpanel
         * @package naanal
         * @var string 
         */
	public $controlpanel=null;
        /**
         * mode
         * @package naanal
         * @var string 
         */
	public $mode="create";
	
	/**
         * redirect
         * @package naanal
         * @var type 
         */
	private $redirect=null;
	
	/**
         * construct
         * @package naanal
         * @param string $controlpanel
         */
	function __construct()
	{
		$this->pdo=ClsLPDO::getInstance("permission");
	}
	/**
         * getRedirect
         * @package naanal
         * @return string
         */
	function getRedirect()
	{
		return $this->redirect;
	}
	/**
         * insert
         * @package naanal
         */
	function insert()
	{       
		$this->mode="insert";
		$sql="insert into `permission` (`feature_id`,`permission`) values (:feature_id,:permission)";
		$obj=new ClsWPermission();
		$obj->setArray($this->request);
      	$this->pdo->setQuery($sql,$obj);
      	$this->redirect="{$this->urlModuleParam}=permission&{$this->urlActionParam}=list";
	}
	/**
         * update
         * @package naanal
         */
	function update()
	{
		$this->mode="update";
		$sql="update `permission` set feature_id=:feature_id,permission=:permission where `id`=:id";
		$obj=new ClsWPermission();
		$obj->setArray($this->request);
	    $this->pdo->setQuery($sql,$obj);
	    $this->redirect="{$this->urlModuleParam}=permission&{$this->urlActionParam}=list";
	}
	/**
         * edit
         * @package naanal
         * @return array
         */
	function edit()
	{
		$this->mode="edit";
		$sql="select * from permission where id='{$this->request["id"]}'";
		$this->pdo->setQuery($sql);
		$obj=new ClsWPermission();
		$obj=$this->pdo->getObject("ClsWPermission");
		return array("form"=>$obj);
	}
	/**
         * create
         * @package naanal
         */
	function create()
	{
		$this->mode="create";
	}
	/**
         * delete
         * @package naanal
         */
	function delete()
	{
		$this->mode="delete";
		$obj=new ClsWPermission();
		$obj->set_id($this->request["id"]);
  		$sql="delete from `permission` where `id`=:id";
  		$this->pdo->setQuery($sql,$obj);
  		$this->redirect="{$this->urlModuleParam}=permission&{$this->urlActionParam}=list";
	}
	/**
         * show list
         * @package naanal
         * @return array
         */
	function show_list()
	{
		$this->mode="list";
		$sql="select * from permission";
		$this->pdo->setQuery($sql);
		$arrObj=$this->pdo->getAllObject("ClsWPermission");
		return array("list"=>$arrObj);		
	}
	/**
         * render
         * @package naanal
         * @return string
         */
	function render()
	{     
		$mode=$this->mode;
		if($mode=="list")
			return $this->show_list();
		else
			return $this->$mode();
	}
}
?>